import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/10 22:44
 */

public class Solution {
    public int rob(int[] nums) {
        int n = nums.length;
        return Math.max(nums[0] + rob1(nums, 2, n - 2), rob1(nums, 1, n - 1));
    }

    private int rob1(int[] nums, int left, int right) {
        if (left > right) {
            return 0;
        }
        int n = nums.length;
        // 定义两个数组f和g，用于存储动态规划的结果
        int[] f = new int[n];
        int[] g = new int[n];
        // 初始化f[left]为数组中left位置的值
        f[left] = nums[left];
        // 从left+1开始遍历到right
        for (int i = left + 1; i <= right; i++) {
            // f[i]表示偷到第i个房子时的最大收益，等于g[i-1]加上第i个房子的值
            f[i] = g[i - 1] + nums[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
            // g[i]表示偷到第i个房子时的最大收益，等于g[i-1]和f[i-1]中的较大值
        }
        // 返回f[right]和g[right]中的较大值，即为偷到第right个房子时的最大收益
        return Math.max(f[right], g[right]);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.rob(nums));
        }
    }
}